package com.java.netty.nio.netty.protocoltcp;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author: Dgg
 * @Date: 2022/1/23 17:29
 */
public class MyServer {

	public static void main(String[] args) {
		EventLoopGroup bossGourp = new NioEventLoopGroup(1);
		EventLoopGroup workerGroup = new NioEventLoopGroup(1);
		try {
			ServerBootstrap serverBootstrap = new ServerBootstrap();
			serverBootstrap.group(bossGourp, workerGroup)
					.channel(NioServerSocketChannel.class)
					.childHandler(new MyTcpServerInitiaLizer());//自定义初始化类

			ChannelFuture channelFuture = serverBootstrap.bind(6665).sync();
			channelFuture.channel().closeFuture().sync();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			bossGourp.shutdownGracefully();
			workerGroup.shutdownGracefully();
		}
	}
}
